#include "BoxDataTable.h"
#include "DataExportCellVisitor.h"
#include "../../LogConf.h"

#include <sstream>
#include <iostream>

namespace jm4bbx {
	void exportData(const BoxDataTable* dataSource, 
		DataExportTarget* dataTarget) {

			const size_t columns = dataSource->getColumnCount();
			const size_t rows = 
				columns > 0 ? dataSource->getColumn(0)->getCellCount() : 0;

			//JM_USE_LOGGER(commonBbx_tables_exportData_logger)
			//LOG_I("Exportovat data v " << rows << " riadkov a " << columns 
			//	<< " stlpcoch." );

			DataExportCellVisitor visitor(dataTarget);
			for (size_t colIndex = 0; colIndex < columns; ++colIndex) {
				BoxDataTable::ColumnPtr column = dataSource->getColumn(colIndex);
				for (size_t rowIndex = 0; rowIndex < rows; ++ rowIndex) {

			/*		LOG_I("Exportovat data [ " << rowIndex << "," << colIndex
						<< "]" );
*/

					//std::stringstream ss;
					//ss << "Exportovat data [ " << rowIndex << "," << colIndex
					//	<< "]\n";
					//std::cout << ss.str()  << std::flush;

					BoxDataTable::Column::CellPtr val = column->getCell(rowIndex);

					visitor.setContext(rowIndex, colIndex);
					val->acceptVisitor(&visitor);

				}
			}
	}
} // namespace jm4bbx
